#include <stdio.h>
#include <stdbool.h>
#include <time.h>
void swapVal(int *nums, int *numSize)
{
    int swap = *nums;
    *nums = *numSize;
    *numSize = swap;
}

void bubbleSort(int *nums, int numSize)
{
    bool sorted = true;
    for (int i = numSize; i > 0; i--)
    {
        for (int idx = 1; idx < numSize; idx++)
        {
            if (nums[idx] < nums[idx - 1])
            {
                swapVal(&(nums[idx]), &(nums[idx - 1]));
            }
        }
        if (sorted == true)
        {
            break;
        }
    }
}

void printArray(int *nums, int numSize)
{
    for (int i = 0; i < numSize; i++)
    {
        printf("%d ", nums[i]);
    }
    printf("\n");
}

int main()
{
    srand(time(NULL));

    int str[6] = {29, 16, 26, 24, 0, 6};
    int length = sizeof(str) / sizeof(str[0]);
    bubbleSort(str, length);
    printArray(str, length);
    /*记录开始时间 */
    clock_t start = clock();
    bubbleSort(str, length);
    /*记录结束时间 */
    clock_t end = clock();
    // 计算运行时间(秒)
    double runtime = (double)(end - start) / CLOCKS_PER_SEC;
    printf("优化后执行时间:%f\n",runtime);
    return 0;
}